﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Dummy.Web
{
    public class GameDataGamer
    {
        public string gamerName { get; private set; }
        public GameClientCallback callback { get; private set; }

        public string startWord { get; private set; }
        public int score { get; private set; }
        public string gamerCompetitorName { get; private set; }
        public DateTime nextMoveDeadline { get; private set; }
        public bool yourMove { get; private set; }
        public bool isPlaying { get; private set; }

        List<string> _words = new List<string>();

        public GameDataGamer(string _gamerName, GameClientCallback _callback)
        {
            gamerName = _gamerName;
            callback = _callback;
            isPlaying = false;
        }

        public bool StartGame(string _gamerCompetitorName, bool _yourMove, string _startWord)
        {
            if (isPlaying)
                return false;
            startWord = _startWord;
            score = 0;
            gamerCompetitorName = _gamerCompetitorName;
            yourMove = _yourMove;
            _words.Clear();
            if (yourMove)
                nextMoveDeadline = DateTime.Now.AddMinutes(2);
            return true;
        }

        public bool IsWordInYourWords(string word)
        {
            return _words.Contains(word.ToLower());
        }

        public string[] GetWordsList()
        {
            return _words.ToArray();
        }

        public bool IsRunOutOfTime()
        {
            if (!yourMove)
                return false;
            return (nextMoveDeadline < DateTime.Now);
        }

        public bool MakeMove(string newword)
        {
            _words.Add(newword.ToLower());
            score += newword.Length;
            yourMove = false;
            return true;
        }

        public bool TakeMove()
        {
            yourMove = true;
            nextMoveDeadline = DateTime.Now.AddMinutes(2);
            return true;
        }
    }
}